// 
//  Copyright (C) 1998-2007 J. Andrew McLaughlin
//  
//  This library is free software; you can redistribute it and/or modify it
//  under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation; either version 2.1 of the License, or (at
//  your option) any later version.
//
//  This library is distributed in the hope that it will be useful, but
//  WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
//  General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this library; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//  process.h
//


#if !defined(_PROCESS_H)

#include <string.h>

#define MAX_PROCNAME_LENGTH  64
#define MAX_PROCESSES        ((GDT_SIZE - RES_GLOBAL_DESCRIPTORS))

#define WAIT_STATE_TIMER (1 << 0)
#define WAIT_STATE_BLOCK (1 << 1)
#define WAIT_STATE_FAST_NOTIFY (1 << 2)
#define WAIT_STATE_EVENT (1 << 3)

// An enumeration listing possible process states
typedef enum {
	proc_starting,   // Process is just created and not yet initialized.
	proc_running,    // Process is running right now.
	proc_ready,      // Process is ready to run and waiting for free processor.
	proc_waiting,    // Process is waiting for timeout or child process.
	proc_sleeping,   // Process is sleeping, and the scheduler does not allocate timeslices to it.
	proc_terminated, // Process is about to be finished.
	proc_finished,   // Process is finished and prepared to be deleted.
	proc_zombie      // Process is finished, but the system failed to delete it.
} processState;

// An enumeration listing possible process types
typedef enum {
  proc_normal, proc_thread
} processType;

typedef struct {
  void *virtualAddress;
  void *entryPoint;
  void *code;
  unsigned codeSize;
  void *data;
  unsigned dataSize;
  unsigned imageSize;
  char commandLine[MAXSTRINGLENGTH];
  int argc;
  char *argv[64];

} processImage;

typedef struct {
  char processName[MAX_PROCNAME_LENGTH];
  int userId;
  int processId;
  processType type;
  int priority;
  int boost;
  int privilege;
  int parentProcessId;
  int descendentThreads;
  int cpuPercent;
  processState state;
  unsigned waitState;
} process;

#define EVENT_FLAG_NO_READ (1 << 0)
#define EVENT_FLAG_NO_WAIT (1 << 1)
#define EVENT_FLAG_CUT     (1 << 2)
#define EVENT_FLAG_UNBLOCK (1 << 3)

#define _PROCESS_H
#endif
